/*
 * @Author: your name
 * @Date: 2020-03-01 15:00:49
 * @LastEditors: komons
 * @LastEditTime: 2020-03-04 17:53:23
 * @Description: 账单工具
 * @FilePath: \form-builderc:\Komons\学习\visualization\src\utils\billUtils.js
 */
export const formatUnits = value => {
  value = Number(value);
  let money = 0;
  if (!value) {
    return false;
  }
  money = value / 100000000;
  if (money >= 1) {
    return {
      money,
      unit: "亿元"
    };
  }
  money = value / 10000;
  if (money > 1) {
    return {
      money,
      unit: "万元"
    };
  }
  return {
    money: value,
    unit: "元"
  };
};

export const numberToFixed = (money = 0, rate = 2) => {
  const tempMoney = money.toString();
  const index = tempMoney.indexOf(".");
  if (index > -1) {
    return tempMoney.substr(0, index + rate + 1);
  } else {
    return money;
  }
};
